package com.xbongbong.pro.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @Author shian
 * @create 2019-08-28 17:10
 * @Description
 */
@Getter
public enum SoukeNumTypeEnum {

    // 搜客的套餐人数分类
    TRIAL_MEAL(0, "enum.soukeNumType.name.trial_meal", "trialMeal", 0),
    ELITE_FIVE_MEAL(5, "enum.soukeNumType.name.elite_five_meal", "eliteMeal", 4),
    BUSINESS_TEN_MEAL(10, "enum.soukeNumType.name.business_ten_meal", "businessMeal", 19),
    ENTERPRISE_THIRTY_MEAL(30, "enum.soukeNumType.name.enterprise_thirty_meal", "enterPriseMeal", 1500);

    private Integer num;

    private String name;

    private String alias;

    private Integer extraSubCount;

    SoukeNumTypeEnum(Integer num, String name, String alias, Integer extraSubCount) {
        this.num = num;
        this.name = name;
        this.alias = alias;
        this.extraSubCount = extraSubCount;
    }

    public static int getByNum(int num){
        for (SoukeNumTypeEnum typeEnum :values()) {
            if (Objects.equals(typeEnum.getNum(), num)) {
                return num;
            }
        }
        return 0;
    }

    public static String getByName(int num){
        for (SoukeNumTypeEnum typeEnum :values()) {
            if (Objects.equals(typeEnum.getNum(), num)) {
                return typeEnum.getName();
            }
        }
        return "";
    }

    public static int getExtraSubCount(int num){
        for (SoukeNumTypeEnum typeEnum :values()) {
            if (Objects.equals(typeEnum.getNum(), num)) {
                return typeEnum.getExtraSubCount();
            }
        }
        return 0;
    }

    public static JSONArray toJSONArray(){
        JSONArray enums = new JSONArray();
        JSONObject object;
        for (SoukeNumTypeEnum soukeNumTypeEnum : values()) {
             object = new JSONObject();
             object.put("nun", soukeNumTypeEnum.getNum());
             object.put("name", soukeNumTypeEnum.getName());
             object.put("extraSubCount", soukeNumTypeEnum.getExtraSubCount());
             enums.add(object);
        }
        return enums;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
